<template>
  <div class="page-box">
    <!-- v-if="tableList.length" -->
    <!-- <searchCom :placeholder="'请输入提交人姓名'" @searchCallBack="searchCallBack" ref="search" /> -->
    <div v-if="tableList.length==0&&isSuccess" style="top:48%" class="start-box  topCen">
      <van-button class=" cursor maxWidthPercentEighty " @click='$openPage("/score/selfEvaluation")' style="width:80%" type="info">开始自评</van-button>
    </div>
    <listCom>
      <div slot="main">
        <van-cell-group style="padding-left:66px; cursor: pointer;" @click="$openPage('/score/selfEvaluationDetails',item)" class="van-cell-group-box cursor" v-for="(item,index) of  tableList" :key="index">
          <van-cell :title="item.quarter_name" :value-class="representations_status[item.is_appeal].state" :value="representations_status[item.is_appeal].lable" :is-link="true" />
          <div v-if="item.is_appeal==4&&!item.is_confirm" @click.stop="examine_toAppeal(item)" class="van-cell-delete error  cenCen">
            <van-button type="info" size="mini">申述</van-button>
          </div>
          <div v-if="item.me_score||item.end_score" class="moScore_box">
            <div v-if="item.me_score">
              自我评分：{{item.me_score}}分 {{gradeInit(item.me_score).gradeadd}}
              <!-- <div class="sure_score cursor">确认评分</div> -->
              <van-button v-if="item.approve_status==1&&item.is_confirm==0&&item.is_appeal==4" @click.stop="score_confirmScore(item)" class="sure_score cursor" size="mini" plain type="primary">确认评分</van-button>
              <van-button v-if="item.is_confirm==1" class="sure_score " size="mini" plain type="primary">已确认评分</van-button>
            </div>
            <div v-if="item.end_score&&item.is_appeal==4">
              最终得分：{{item.end_score}}分 {{gradeInit(item.end_score).gradeadd}}
              <!-- <van-button class="sure_score cursor" size="mini" plain type="info">申述</van-button> -->
              <!-- <div>申述</div> -->
            </div>
          </div>
        </van-cell-group>
      </div>
    </listCom>
  </div>
</template>
<script>
import searchCom from "@/components/search/index.vue"; //搜索组件
import listCom from "@/components/list/index.vue"; //表格列表组件
import service from "@/api";
import { grade } from "@/components/js/grade.js";
import representations_status from "@/components/js/representations_status";
export default {
  components: { searchCom, listCom },
  data() {
    return {
      representations_status: representations_status,
      isSuccess: false, //是否请求数据了
      tableList: [] //表格数据
    };
  },
  mounted() {
    this.setRight();
    this.score_listExamine();
  },
  methods: {
    // 设置头部右侧按钮
    async setRight() {
      if (await this.$ddApi.isDDMobilePlatform()) {
        const res = await this.$ddApi.setRight(true, true, "开始自评");
        if (res) {
          this.$openPage("/score/selfEvaluation");
        }
      } else {
        this.$store.state.navBarRight.title = "开始自评";
        let t = this;
        this.$store.state.navBarRight.callBackFun = function openPage() {
          t.$openPage("/score/selfEvaluation");
        };
      }
    },
    // 等级初始化
    gradeInit(me_score) {
      return grade(me_score);
    },
    // 搜索的换掉函数
    async searchCallBack(val) {
      this.$toast("更新中，请稍后再试");
      return;
      this.$store.state.loading = true;
      this.$store.state.loadingText = "获取数据中";
      this.isSuccess = false;
      const { data = [] } = await service.scoreApproval_listByName({
        start: 0,
        limit: 999999,
        current: 1,
        userName: val
        // status: 1
      });
      this.isSuccess = true;
      this.$store.state.loading = false;
      console.log(data.rows);
      this.tableList = data.rows || [];
    },
    // 确认评分
    async score_confirmScore(item) {
      const alertRes = await this.$alert("此操作将进行确认评分");
      if (!alertRes) {
        return;
      }
      this.$store.state.loading = true;
      this.$store.state.loadingText = "确认评分中";
      const { success = false } = await service.score_confirmScore({
        examine_id: item.id
      });
      this.$store.state.loading = false;
      if (success) {
        this.$toast.success("确认成功");
        this.score_listExamine();
      }
    },
    // 申诉
    async examine_toAppeal(item) {
      const alertRes = await this.$alert("此操作将进行申述");
      if (!alertRes) {
        return;
      }
      this.$store.state.loading = true;
      this.$store.state.loadingText = "确认申述中";
      const { success = false } = await service.examine_toAppeal({
        examine_id: item.id
      });
      this.$store.state.loading = false;
      if (success) {
        this.$toast.success("已申述");
        this.score_listExamine();
      }
    },
    // 查询
    async score_listExamine() {
      this.$store.state.loading = true;
      this.$store.state.loadingText = "获取数据中";
      this.isSuccess = false;
      const { data = [] } = await service.score_listExamine({
        start: 0,
        limit: 999999,
        current: 1
        // status: 1
      });
      this.isSuccess = true;
      this.$store.state.loading = false;
      console.log(data.rows);
      this.tableList = data.rows || [];
      // console.log(this.$refs.search.searchValue);
    }
  }
};
</script>

<style scoped>
@import "./../assessment/index.css";
.moScore_box {
  width: 100%;
  height: auto;
  position: relative;
  padding: 6px 16px;
  text-align: left;
  color: #323233;
  font-size: 14px;
}
.moScore_box > div {
  padding: 2px 0px;
  position: relative;
}
.sure_score {
  position: absolute;
  right: 0px;
  top: 0px;
  /* width: auto;
  height: auto; */
  /* background: #1989fa;
  color: #fff;
  padding: 2px;
  font-size: 12px; */
}
</style>
